From 9aff22bcf54ee98e74981e605b34f6231a915c8b Mon Sep 17 00:00:00 2001 From: "kaf24@scramble.cl.cam.ac.uk" Date: Thu, 20 Nov 2003 23:19:07 +0000 Subject: [PATCH] bitkeeper revision 1.622 (3fbd4bebsTJdb-aVkXDUuIpXoNZ5DA) setup.py, Makefile: A XenoUtil module containing handy helpers for creating control scripts. XenoUtil.py: new file --- .rootkeys | 1 + tools/xc/py/Makefile | 2 +- tools/xc/py/XenoUtil.py | 66 +++++++++++++++++++++++++++++++++++++++++ tools/xc/py/setup.py | 2 ++ 4 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 tools/xc/py/XenoUtil.py diff --git a/.rootkeys b/.rootkeys index 26dfc3af65..f97a848862 100644 --- a/.rootkeys +++ b/.rootkeys @@ -213,6 +213,7 @@ 3fbba6dc1uU7U3IFeF6A-XEOYF2MkQ tools/xc/lib/rpm.spec 3fbba6dcrNxtygEcgJYAJJ1gCQqfsA tools/xc/lib/xc.h 3fbd0a3dTwnDcfdw0-v46dPbX98zDw tools/xc/py/Makefile +3fbd4bd6GtGwZGxYUJPOheYIR7bPaA tools/xc/py/XenoUtil.py 3fbd0a40yT6G3M9hMpaz5xTUdl0E4g tools/xc/py/setup.py 3fbd0a42l40lM0IICw2jXbQBVZSdZg tools/xc/py/xc_py.c 3f72f1bdJPsV3JCnBqs9ddL9tr6D2g xen/COPYING diff --git a/tools/xc/py/Makefile b/tools/xc/py/Makefile index 2357d11ccb..a402cf77b6 100644 --- a/tools/xc/py/Makefile +++ b/tools/xc/py/Makefile @@ -6,4 +6,4 @@ install: python setup.py install clean: - rm -rf build + rm -rf build *.pyc *.pyo *.o *.a *~ diff --git a/tools/xc/py/XenoUtil.py b/tools/xc/py/XenoUtil.py new file mode 100644 index 0000000000..f9b8728290 --- /dev/null +++ b/tools/xc/py/XenoUtil.py @@ -0,0 +1,66 @@ + +import string, re, os + +def blkdev_name_to_number(name): + """Take the given textual block-device name (e.g., '/dev/sda1', + 'hda') and return the device number used by the OS. """ + + if not re.match( '/dev/', name ): + name = '/dev/' + name + + fd = os.popen( '/bin/ls -lL ' + name + ' 2>/dev/null' ) + line = fd.readline() + + #brw-rw---- 1 root mail 8, 3 Aug 30 2001 /dev/sda3 + m = re.search( '^b\S+\s+\d+\s+\S+\s+\S+\s+(\d+),\s+(\d+)\s+\S+\s+\d+' + + '\s+\d+\s+' + name + '$', line ) + + if m: + # hack -- we just assume device minors are 8 bits + return (string.atol(m.group(1)) << 8) + string.atol(m.group(2)) + return None + + +# lookup_blkdev_partn_info( '/dev/sda3' ) +def lookup_blkdev_partn_info(partition): + """Take the given block-device name (e.g., '/dev/sda1', 'hda') + and return a information tuple ( partn-dev, disc-dev, start-sect, + nr-sects, type ) + partn-dev: Device number of the given partition + disc-dev: Device number of the disc containing the partition + start-sect: Index of first sector of the partition + nr-sects: Number of sectors comprising this partition + type: 'Disk' or identifying name for partition type + """ + + if not re.match( '/dev/', partition ): + partition = '/dev/' + partition + + drive = re.split( '[0-9]', partition )[0] + + if drive == partition: + fd = os.popen( '/sbin/sfdisk -s ' + drive + ' 2>/dev/null' ) + line = fd.readline() + if line: + return ( blkdev_name_to_number(drive), + blkdev_name_to_number(drive), + 0, + string.atol(line) * 2, + 'Disk' ) + return None + + # determine position on disk + fd = os.popen( '/sbin/sfdisk -d ' + drive + ' 2>/dev/null' ) + + #['/dev/sda3 : start= 16948575, size=16836120, Id=83, bootable\012'] + lines = fd.readlines() + for line in lines: + m = re.search( '^' + partition + '\s*: start=\s*([0-9]+), ' + + 'size=\s*([0-9]+), Id=\s*(\S+).*$', line) + if m: + return ( blkdev_name_to_number(partition), + blkdev_name_to_number(drive), + string.atol(m.group(1)), + string.atol(m.group(2)), + m.group(3) ) + return None diff --git a/tools/xc/py/setup.py b/tools/xc/py/setup.py index 59096039fa..8da21e5c61 100644 --- a/tools/xc/py/setup.py +++ b/tools/xc/py/setup.py @@ -14,3 +14,5 @@ module.extra_objects = ["../lib/libxc.a"] module.libraries = ["z"] setup(name = "Xc", version = "1.0", ext_modules = [module]) + +setup(name = "XenoUtil", version = "1.0", py_modules = ["XenoUtil"]) -- 2.30.2